package edu.udo.sopra10.chaturaji.events;

import edu.udo.sopra10.chaturaji.entities.Player;
import edu.udo.sopra10.chaturaji.entities.Turn;

/**
 * Request event that is invoked when a turn should be made.
 * 
 * @author Patrick Westerhoff
 */
public class TurnRequestEvent extends ChaturajiEvent
{
	private static final long serialVersionUID = -2805046586611944365L;
	
	private int turnNumber;
	private byte playerId;
	private Player.Type playerType;
	
	/**
	 * Constructs a turn request event based on the empty {@link Turn} entity.
	 * 
	 * @param source the source object.
	 * @param turn the turn entity this event is based on.
	 */
	public TurnRequestEvent ( Object source, Turn turn )
	{
		super( source );
		
		Player player = turn.getPlayer();
		
		// copy data from turn
		turnNumber = (int) Math.floor( player.getGame().getHistory().indexOf( turn ) / 4 );
		playerId = player.getTurnOrderPosition();
		playerType = player.getType();
	}
	
	/**
	 * Returns the current turn number.
	 * 
	 * @return the turn number.
	 */
	public int getTurnNumber ()
	{
		return turnNumber;
	}
	
	/**
	 * Returns the id of the current player.
	 * 
	 * @return the player id.
	 */
	public byte getPlayerId ()
	{
		return playerId;
	}
	
	/**
	 * Returns the type of the current player.
	 * 
	 * @return the player type.
	 */
	public Player.Type getPlayerType ()
	{
		return playerType;
	}
}